//index.js
//获取应用实例
const app = getApp()
const Pager = require('components/aotoo/core')

let mkScrenn = require('components/modules/screen')
let mkDropdownList = require('components/modules/dropdownlist')

const xx0 = mkDropdownList({$$id: 'dd-list-radio-0', parentId: '0', type: 'radio', data: []})
const xx1 = mkDropdownList({$$id: 'dd-list-checkbox', parentId: '1', type: 'checkbox'})
const xx2 = mkDropdownList({$$id: 'dd-list-radio-2', parentId: '2', type: 'radio'})
const xx3 = mkDropdownList({$$id: 'dd-list-radio-3', parentId: '3', type: 'radio'})

const data = {
  0: [{title: '从远到近', id: 'a1'}, {title: '从近到远', id: 'b1'}, {title: '附近', id: 'c1'}],
  1: [{title: '200m以内的', id: 'a1'}, {title: '500m以内的', id: 'b1'}, {title: '1km以内的', id: 'c1'}],
  2: [{title: '便宜', id: 'a1'}, {title: '舒适', id: 'b1'}, {title: '品质', id: 'c1'}],
  3: [{title: '便宜', id: 'a1'}, {title: '舒适', id: 'b1'}, {title: '品质', id: 'c1'}]
}

Pager({
  data: {
    pages: mkScrenn({
      $$id: 'dd-screen-2',
      menus: [{title: '位置', type: 'radio', id: '0'}, {title: '车程距离', type: 'checkbox',id: '1'}, {title: '热门城市', type: 'radio', id: '2'}, {title: '自驾主题', type: 'radio', id: '3'}],
      contents: [
        xx0, xx1, xx2, xx3
      ],
      itemClass: 'dropdown-item-content',
      itemWidth: '25%',
      aysncItem: true
      // mask: false
    })
  },
  $screenInst2: null,
  onShow: function () {},
  
  checkedIdx: [],

  onReady: function () {
    const that = this
    this.$screenInst2 = this.getElementsById('dd-screen-2')
    this.$Inst = {
      0: this.getElementsById('dd-list-radio-0'),
      1: this.getElementsById('dd-list-checkbox'),
      2: this.getElementsById('dd-list-radio-2'),
      3: this.getElementsById('dd-list-radio-3'),
    }
    
    //点击菜单 拉取数据
    this.$screenInst2.hooks.on('updateContent', function (params) {
      const parentId = parseInt(params.id)
      that.$Inst[params.id].updatex(data[parentId])
    })

    this.$Inst[0].hooks.on('dropdownlist-radio', function(params) {
      const _vals = params.vals
      const _parentId = params.parentId
      that.$screenInst2.onClose({parentId: _parentId, vals: _vals})
    })
    this.$Inst[2].hooks.on('dropdownlist-radio', function(params) {
      const _vals = params.vals
      const _parentId = params.parentId
      that.$screenInst2.onClose({parentId: _parentId, vals: _vals})
    })
    this.$Inst[3].hooks.on('dropdownlist-radio', function(params) {
      const _vals = params.vals
      const _parentId = params.parentId
      that.$screenInst2.onClose({parentId: _parentId, vals: _vals})
    })
    this.$Inst[1].hooks.on('keep-val', function(params) {
      const _vals = params.vals
      const _parentId = params.parentId
      that.$screenInst2.onClose({parentId: _parentId, vals: _vals})
    })
  },
  radioUpdate(instName) {
    // const that = this
    // instName.hooks.on('dropdownlist-radio', function(params) {
    //   const _vals = params.vals
    //   const _parentId = params.parentId
    //   that.$screenInst2.onClose({parentId: _parentId, vals: _vals})
    // })
  },
  onLoad: function () {},
})
